package com.xiaolun.stream;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class StreamDemo02 {
	public static void main(String[] args) {
		functionTest();
		predicateTest();
		consumerTest();
		supplierTest();
	}

	//1、函数式接口<String, Integer><输入类型，输出类型>
//		Function <String, Integer> function = new Function<String, Integer>() {
//			@Override
//			public Integer apply(String s) {
//				return 1024;
//			}
//		};
	private static void functionTest() {
		Function<String, Integer> function = (s) -> {
			return 1024;
		};
		System.out.println(function.apply("abc")); //1024
	}

	//2、断定型接口 输入参数类型 String,返回boolean类型
//		Predicate<String> predicate = new Predicate<String>() {
//			@Override
//			public boolean test(String s) {
//				return false;
//			}
//		};
	private static void predicateTest() {
		Predicate<String> predicate = (s) -> {
			return s.isEmpty();
		};
		System.out.println(predicate.test("abc"));  //false
	}

	//3、消费型接口 输入类型 输出为void
	//		Consumer<String> consumer = new Consumer<String>() {
//			@Override
//			public void accept(String s) {
//
//			}
//		};

	private static void consumerTest() {
		Consumer<String> consumer = (s) -> {
			System.out.println("进入消费数据接口中");
		};
		consumer.accept("param");
	}

	//4、供给型接口(和消费者相反) 无输出参数，又赶回参数
//		Supplier<String> supplier = new Supplier<String>() {
//			@Override
//			public String get() {
//				return null;
//			}
//		};
	private static void supplierTest() {
		Supplier<String> supplier = () -> {
			return "hello world!";
		};
		System.out.println(supplier.get());
	}
}
